package com.home.cop.employee.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.home.cop.employee.mapper.DepartmentMapper;
import com.home.cop.employee.model.Department;
import com.home.cop.employee.service.DepartmentService;
import com.home.cop.system.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper depetMapper;

    @Override
    public PageInfo<Department> list(Map<String, Object> params, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Department> list = depetMapper.list(params);
        return new PageInfo<>(list);
    }

    @Override
    public List<Department> getAllDepts() {
        return depetMapper.getAllDepts();
    }

    @Transactional
    @Override
    public void insert(Department department) {
        depetMapper.insert(department);
    }

    @Transactional
    @Override
    public void delete(Integer deptId) {
        depetMapper.deleteByPrimaryKey(deptId);
    }

    @Transactional
    @Override
    public void updateInfo(Department department) {
        depetMapper.updateByPrimaryKeySelective(department);
    }
}
